<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  

  
  <title>CSS基础知识点--选择器 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="种类 标签选择器  类选择器  ID选择器  全局选择器  群组选择器  后代选择器   伪类选择器 伪类选择器定义特殊状态下的样式  无法用标签、id、class及其他属性实现   链接伪类链接的4种状态：激活状态，已访问状态，未访问状态和鼠标悬停状态    伪类 说明    :link 未访问的链接   :visited 已访问的链接   :hover 鼠标悬停状态   :active 激活">
<meta name="keywords" content="CSS">
<meta property="og:type" content="article">
<meta property="og:title" content="CSS基础知识点--选择器">
<meta property="og:url" content="http://yoursite.com/2019/07/31/CSS基础知识点-选择器/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="种类 标签选择器  类选择器  ID选择器  全局选择器  群组选择器  后代选择器   伪类选择器 伪类选择器定义特殊状态下的样式  无法用标签、id、class及其他属性实现   链接伪类链接的4种状态：激活状态，已访问状态，未访问状态和鼠标悬停状态    伪类 说明    :link 未访问的链接   :visited 已访问的链接   :hover 鼠标悬停状态   :active 激活">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2019-08-01T05:55:12.487Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="CSS基础知识点--选择器">
<meta name="twitter:description" content="种类 标签选择器  类选择器  ID选择器  全局选择器  群组选择器  后代选择器   伪类选择器 伪类选择器定义特殊状态下的样式  无法用标签、id、class及其他属性实现   链接伪类链接的4种状态：激活状态，已访问状态，未访问状态和鼠标悬停状态    伪类 说明    :link 未访问的链接   :visited 已访问的链接   :hover 鼠标悬停状态   :active 激活">
  
    <link rel="alternate" href="/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-CSS基础知识点-选择器" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2019/07/31/CSS基础知识点-选择器/" class="article-date">
  <time datetime="2019-07-31T10:32:51.000Z" itemprop="datePublished">2019-07-31</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/CSS/">CSS</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      CSS基础知识点--选择器
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <hr>
<h2 id="种类"><a href="#种类" class="headerlink" title="种类"></a>种类</h2><ul>
<li><p>标签选择器</p>
</li>
<li><p>类选择器</p>
</li>
<li><p>ID选择器</p>
</li>
<li><p>全局选择器</p>
</li>
<li><p>群组选择器</p>
</li>
<li><p>后代选择器</p>
</li>
</ul>
<h2 id="伪类选择器"><a href="#伪类选择器" class="headerlink" title="伪类选择器"></a>伪类选择器</h2><ul>
<li><p>伪类选择器定义特殊状态下的样式</p>
</li>
<li><p>无法用标签、id、class及其他属性实现</p>
</li>
</ul>
<h3 id="链接伪类"><a href="#链接伪类" class="headerlink" title="链接伪类"></a>链接伪类</h3><p>链接的4种状态：激活状态，已访问状态，未访问状态和鼠标悬停状态</p>
<table>
<thead>
<tr>
<th>伪类</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>:link</td>
<td>未访问的链接</td>
</tr>
<tr>
<td>:visited</td>
<td>已访问的链接</td>
</tr>
<tr>
<td>:hover</td>
<td>鼠标悬停状态</td>
</tr>
<tr>
<td>:active</td>
<td>激活的链接</td>
</tr>
</tbody></table>
<h4 id="链接伪类的顺序"><a href="#链接伪类的顺序" class="headerlink" title="链接伪类的顺序"></a>链接伪类的顺序</h4><p>:link &gt; :visited &gt; :hover &gt; :active</p>
<p>说明：</p>
<ol>
<li><p>a:hover必须置于a:link和a:visited之后，才有效</p>
</li>
<li><p>a:active必须置于a:hover之后，才有效</p>
</li>
<li><p>伪类名称对大小写不敏感</p>
</li>
</ol>
<h3 id="伪类-hover和-active"><a href="#伪类-hover和-active" class="headerlink" title="伪类:hover和:active"></a>伪类:hover和:active</h3><ol>
<li><p>:hover用于访问的鼠标经过某个元素时</p>
</li>
<li><p>:active用于一个元素被激活时（即按下鼠标之后放开鼠标之前的时间）</p>
</li>
</ol>
<h4 id="伪类-hover和-active兼容"><a href="#伪类-hover和-active兼容" class="headerlink" title="伪类:hover和:active兼容"></a>伪类:hover和:active兼容</h4><ul>
<li><p>IE6及更早版本，支持<code>&lt;a&gt;</code>元素的4种状态</p>
</li>
<li><p>IE6浏览器不支持元素的:hover和:active</p>
</li>
</ul>
<h2 id="CSS层叠"><a href="#CSS层叠" class="headerlink" title="CSS层叠"></a>CSS层叠</h2><ul>
<li><p>可以定义多个样式</p>
</li>
<li><p>不冲突时，多个样式课层叠为一个</p>
</li>
<li><p>冲突时，按不同样式规则优先级来应用样式</p>
</li>
</ul>
<h2 id="CSS选择器优先级"><a href="#CSS选择器优先级" class="headerlink" title="CSS选择器优先级"></a>CSS选择器优先级</h2><p>id选择器 &gt; class选择器 &gt; 标签选择器 &gt; 通配符</p>
<p>同一元素使用相同类型的选择器定义相同类型样式，优先级按就近原则</p>
<h2 id="CSS优先级规则"><a href="#CSS优先级规则" class="headerlink" title="CSS优先级规则"></a>CSS优先级规则</h2><p>同一样式表中：</p>
<ol>
<li>权值相同</li>
</ol>
<ul>
<li>就近原则（离被设置元素越近优先级越高）</li>
</ul>
<ol start="2">
<li>权值不同</li>
</ol>
<ul>
<li><p>根据权值来判断CSS样式</p>
</li>
<li><p>哪种CSS样式权值越高，就使用哪种样式</p>
</li>
</ul>
<h2 id="选择器权值"><a href="#选择器权值" class="headerlink" title="选择器权值"></a>选择器权值</h2><table>
<thead>
<tr>
<th>选择器</th>
<th>权值</th>
</tr>
</thead>
<tbody><tr>
<td>标签选择器</td>
<td>1</td>
</tr>
<tr>
<td>类选择器</td>
<td>10</td>
</tr>
<tr>
<td>伪类</td>
<td>10</td>
</tr>
<tr>
<td>ID选择器</td>
<td>100</td>
</tr>
<tr>
<td>通配符选择器</td>
<td>0</td>
</tr>
<tr>
<td>行内样式</td>
<td>1000</td>
</tr>
</tbody></table>
<h3 id="权值规则"><a href="#权值规则" class="headerlink" title="权值规则"></a>权值规则</h3><ol>
<li><p>统计不同选择器的个数</p>
</li>
<li><p>每类选择器的个数乘以相应权值</p>
</li>
<li><p>把所有的值相加得出选择器的权值</p>
</li>
</ol>
<h3 id="important规则"><a href="#important规则" class="headerlink" title="!important规则"></a>!important规则</h3><ul>
<li><p>可调整样式规则的优先级，使其权值最高</p>
</li>
<li><p>添加在样式规则之后，中间用空格隔开</p>
</li>
</ul>
<h2 id="CSS样式命名规则"><a href="#CSS样式命名规则" class="headerlink" title="CSS样式命名规则"></a>CSS样式命名规则</h2><ul>
<li><p>采用英文字母、数字以及”-“和”_”命名</p>
</li>
<li><p>以小写字母开头，不能以数字和”-“、”_”开头</p>
</li>
<li><p>命名形式：单字，连字符，下划线和驼峰</p>
</li>
<li><p>使用有意义命名</p>
</li>
</ul>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2019/07/31/CSS基础知识点-选择器/" data-id="ck4r400nh000ml0w01aahq42v" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/CSS/">CSS</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2019/08/01/CSS基础知识点-CSS样式命名/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          CSS基础知识点--CSS样式命名
        
      </div>
    </a>
  
  
    <a href="/2019/07/30/CSS基础知识点/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">CSS基础知识点</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Ajax/">Ajax</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/CSS/">CSS</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/CSS3/">CSS3</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Dart/">Dart</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Flutter/">Flutter</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Git/">Git</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/HTML/">HTML</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/HTML5/">HTML5</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/JSON/">JSON</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/QT/">QT</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/React/">React</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/Sass/">Sass</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/TheKnowledgeOf/">TheKnowledgeOf</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/TypeScript/">TypeScript</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/bootstrap/">bootstrap</a></li><li class="category-list-item"><a class="category-list-link" href="/categories/jQuery/">jQuery</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Ajax/">Ajax</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CSS/">CSS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CSS3/">CSS3</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Dart/">Dart</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Flutter/">Flutter</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Git/">Git</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/HTML/">HTML</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/HTML5/">HTML5</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JSON/">JSON</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java/">Java</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JavaScript/">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Javascript/">Javascript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/QT/">QT</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/React/">React</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Sass/">Sass</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TheKnowledgeOf/">TheKnowledgeOf</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TypeScript/">TypeScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/bootstrap/">bootstrap</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/jQuery/">jQuery</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Ajax/" style="font-size: 12.22px;">Ajax</a> <a href="/tags/CSS/" style="font-size: 18.89px;">CSS</a> <a href="/tags/CSS3/" style="font-size: 17.78px;">CSS3</a> <a href="/tags/Dart/" style="font-size: 14.44px;">Dart</a> <a href="/tags/Flutter/" style="font-size: 16.67px;">Flutter</a> <a href="/tags/Git/" style="font-size: 12.22px;">Git</a> <a href="/tags/HTML/" style="font-size: 14.44px;">HTML</a> <a href="/tags/HTML5/" style="font-size: 12.22px;">HTML5</a> <a href="/tags/JSON/" style="font-size: 10px;">JSON</a> <a href="/tags/Java/" style="font-size: 11.11px;">Java</a> <a href="/tags/JavaScript/" style="font-size: 20px;">JavaScript</a> <a href="/tags/Javascript/" style="font-size: 10px;">Javascript</a> <a href="/tags/QT/" style="font-size: 12.22px;">QT</a> <a href="/tags/React/" style="font-size: 15.56px;">React</a> <a href="/tags/Sass/" style="font-size: 11.11px;">Sass</a> <a href="/tags/TheKnowledgeOf/" style="font-size: 11.11px;">TheKnowledgeOf</a> <a href="/tags/TypeScript/" style="font-size: 10px;">TypeScript</a> <a href="/tags/bootstrap/" style="font-size: 11.11px;">bootstrap</a> <a href="/tags/jQuery/" style="font-size: 13.33px;">jQuery</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/12/">December 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/11/">November 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/10/">October 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/09/">September 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/08/">August 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">July 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/06/">June 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/05/">May 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/04/">April 2019</a></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/03/">March 2019</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2019/12/29/Flutter-MaterialApp常用属性介绍/">Flutter-MaterialApp常用属性介绍</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-ListView/">Flutter-ListView</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-AppBar/">Flutter-AppBar</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-TabBar/">Flutter-TabBar</a>
          </li>
        
          <li>
            <a href="/2019/12/29/Flutter-按钮/">Flutter-按钮</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2019 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>